page.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use client";
  2. import { Category, GameListRep, searchGameListApi, SearchProps } from "@/api/home";
  3. import Box from "@/components/Box";
  4. import GroupCard from "@/components/Card/GroupCard";
  5. import HeaderBack from "@/components/HeaderBack";
  6. import { Pagination } from "@/types";
  7. import { useSetState } from "ahooks";
  8. import { InfiniteScroll } from "antd-mobile";
  9. import { FC, useRef } from "react";
  10. interface Props {
  11. searchParams: {
  12. gameListFlag: string;
  13. type: 1 | 2;
  14. bet_type: Category["bet_type"];
  15. name: string;
  16. };
  17. }
  18. const GameListFlag: FC<Props> = (props) => {
  19. const { searchParams } = props;
  20. const [target, setTarget] = useSetState<{ games: GameListRep[]; page: Partial<Pagination> }>({
  21. games: [],
  22. page: { is_end: false },
  23. });
  24. const params = useRef<SearchProps>({
  25. current_page: 0,
  26. page_size: 15,
  27. use_page: true,
  28. });
  29. // 通过类型判断, 1: 游戏 2:厂商
  30. if (+searchParams.type === 2) {
  31. params.current.provider_id = +searchParams.gameListFlag;
  32. } else {
  33. params.current.category_id = +searchParams.gameListFlag;
  34. }
  35. const getGames = async (): Promise<GameListRep[] | undefined> => {
  36. return searchGameListApi(params.current).then((res) => {
  37. if (res.code === 200) {
  38. setTarget((value) => ({ page: res.page, games: [...value.games, ...res.data] }));
  39. return res.data;
  40. }
  41. });
  42. };
  43. const loadMore = async () => {
  44. params.current.current_page += 1;
  45. await getGames();
  46. };
  47. return (
  48. <>
  49. <HeaderBack showBack={true} title={searchParams.name} />
  50. <main className={"main-header bg-[#1f1f1f]"}>
  51. <Box>
  52. <GroupCard
  53. data={target.games}
  54. row={1}
  55. groupType={Number(searchParams.bet_type) as Category["bet_type"]}
  56. />
  57. <InfiniteScroll loadMore={loadMore} hasMore={!target.page.is_end!} />
  58. </Box>
  59. </main>
  60. </>
  61. );
  62. };
  63. export default GameListFlag;